package com.qf.controller;

import com.qf.common.dto.OrderDto;
import com.qf.entity.Order;
import com.qf.service.OrderService;
import com.qf.vo.ResponseResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author KING
 * @ClassName: com.qf.controller.OrderController
 * @Description: 该类的功能描述
 * @date: 2021/10/27 21:27
 */
@RestController
@RequestMapping("/order")
@Validated
public class OrderController {
    @Resource
    private OrderService orderService;

    /**
     * 订单管理---展示该店铺所有的订单信息
     *
     * @param
     * @return
     */
    @PostMapping("/find")
    public ResponseResult<List<Order>> findOrders(@Validated(value = {OrderDto.FindOrder.class})
                                                  @RequestBody OrderDto orderDto) {
        List<Order> orderList = orderService.findOrders(orderDto);
        return ResponseResult.success(orderList);
    }

    /**
     * 根据条件查询订单
     *
     * @param orderDto
     * @return
     */
    @PostMapping("/search")
    public ResponseResult<List<Order>> searchOrders(@Validated(value = {OrderDto.SearchOrder.class})
                                                    @RequestBody OrderDto orderDto) {
        List<Order> orderList = orderService.searchOrders(orderDto);
        return ResponseResult.success(orderList);
    }

    /**
     * 按付款金额排序查询
     *
     * @param sid
     * @param role
     * @return
     */
    @PostMapping("/sort/{sid}/{role}")
    public ResponseResult<List<Order>> sortOrders(@PathVariable("sid") Integer sid, @PathVariable("role") Integer role) {
        List<Order> orderList = orderService.sortOrders(sid, role);
        return ResponseResult.success(orderList);
    }
}
